package com.sky.controller.admin;

import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.result.Result;
import com.sky.service.DishService;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/dish")
public class DishController {
	
	private final DishService dishService;
	
	public DishController(DishService dishService) {this.dishService = dishService;}
	
	@GetMapping("/page")
	public Result dishPage(DishPageQueryDTO pageQueryDTO) {
		return dishService.dishPage(pageQueryDTO);
	}
	
	@PostMapping
	public Result addDish(@RequestBody DishDTO dishDTO) {
		return dishService.addDish(dishDTO);
	}
	
	@DeleteMapping
	public Result deleteDish(@RequestParam List<Long> ids) {
		return dishService.deleteDish(ids);
	}
	
	@GetMapping("/{id}")
	public Result getById(@PathVariable Long id) {
		return dishService.getById(id);
	}
	
	@PutMapping
	public Result updateDish(@RequestBody DishDTO dishDTO) {
		return dishService.updateDish(dishDTO);
	}
	
	@PostMapping("/status/{status}")
	public Result banDish(@PathVariable Integer status, Long id) {
		return dishService.banDish(status, id);
	}
	
	@GetMapping("/list")
	public Result getDishList(Long categoryId) {
		return dishService.getByCategoryId(categoryId);
	}
}
